from typing import List
from common.enum.strategy_group_enum import StrategyGroup
from common.enum.strategy_type_enum import StrategyType
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_assessment import RiskAssessment
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_stock_day import StrategyStockDay
from service.strategy.base_strategy import BaseStrategy


class RiskOnLimitUpButNotCloseStrategy(BaseStrategy):
    """
    风险策略：判断某个股票在当天存在涨停，但收盘不是涨停，构成风险。
    """

    def analyze(self, trade_info_list: List[StrategyStockDay]) -> RiskAssessment:
        """
        分析当天是否存在涨停，但收盘价低于涨停价。
        """
        node_point = 0
        description = ""

        # 确保至少有1天的交易数据
        if len(trade_info_list) >= 1:
            # 获取当天的交易数据（假设是最后一天）
            today = trade_info_list[-1]

            # 根据前收盘价计算涨停价格
            limit_up_price = today.pre_close * 1.1

            # 判断是否涨停
            if today.close == today.high and today.high == limit_up_price:
                # 如果当天涨停，但收盘价不是涨停价
                if today.close < today.limit_up_price:
                    node_point += 5  # 风险较大，得分 +5
                    description += f"股票触及每日涨停点，但收盘价低于涨停点。潜在风险! "

        return RiskAssessment(
            stock_code=trade_info_list[0].stock_code,
            description=description,
            config=self.strategyConfig(),
            node_point=node_point,
        )

    def strategyConfig(self) -> StrategyInfoMetadata:
        """
        返回策略的配置
        """
        return StrategyInfoMetadata(
            strategy_code="risk_on_limit_up_but_not_close",
            strategy_name="涨停但收盘未涨停",
            strategy_group=StrategyGroup.RISK,  # 风险型策略
            strategy_type=StrategyType.PRICE,  # 根据价格类型
            analysis_day=1,
            strategy_level=5,  # 风险较大，策略等级高
        )
